package com.zsp.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zsp.entity.Message;
import com.zsp.entity.param.MessageParam;
import com.zsp.entity.vo.MessageVo;
import com.zsp.mapper.MessageDao;
import com.zsp.result.Result;
import com.zsp.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("MessageService")
public class MessageServiceImpl extends ServiceImpl<MessageDao, Message> implements MessageService {
    @Autowired
    private MessageDao messageDao;



    @Override
    public int verify(Integer id, Integer type) {
        return messageDao.verify(id, type);
    }

    @Override
    public Page<MessageVo> selectPageVo(Page<MessageVo> page) {
        return messageDao.selectPageVo(page);
    }

    @Override
    public Result selectPage(MessageParam param) {

        Page<Message> page = new Page<>(param.getPageNum(), param.getPageSize());

        // 执行查询
        IPage<Message> result = this.page(page,Wrappers.lambdaQuery(Message.class)
                .eq(param.getType()!= null,Message::getType,param.getType()));

       // 分页结果封装
        Result<List<Message>> res = Result.success(result.getRecords());
        res.setTotal(result.getTotal());
        return res;
    }


}
